package com.smart_campus.sys.common;

import com.smart_campus.bus.domain.Comment;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class CommentTreeNode  extends Comment{


    private List<CommentTreeNode> child = new ArrayList<>();


    public static List<CommentTreeNode> bulid(List<CommentTreeNode> treeNodes, Integer topid) {
        List<CommentTreeNode> nodes = new ArrayList<>();
        for ( CommentTreeNode comment :treeNodes) {
            if (comment.getPid()==topid) {
                nodes.add(comment);
            }
            for (CommentTreeNode comment1 : nodes) {
                if (comment1.getPid()==comment.getId()) {
                    comment.getChild().add(comment1);
                }
            }
        }
        return nodes;
    }

}
